#include "progbar.h"

void progress(double rate)
{
    static char buffer[MAX] = {0};
    static char* label = "/-\\|";
    static int cnt = 0;
    int irate = (int)rate;
    if(fabs(rate-100.0) > 1e-6)
        buffer[irate] = HEAD;

    printf("[\033[30;44m%-100s\033[0m][\033[31m%.1lf%%\033[0m][\033[33m%c\033[0m]\r", buffer, rate, label[(cnt++)%4]);
    fflush(stdout);
    
    buffer[irate] = FLAG;
    if(fabs(rate-100.0) <= 1e-6)
        printf("\n");
}
